package cn.pop.hsp_system_v2.Service.impl;

import java.util.List;

import cn.pop.hsp_system_v2.Mapper.SystemUserMapper;
import cn.pop.hsp_system_v2.Pojo.SystemUser;
import cn.pop.hsp_system_v2.Pojo.Vo.SystemUserAndPatientVo;
import cn.pop.hsp_system_v2.Service.ISystemUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 业务登录Service业务层处理
 * 
 * @author pop404NotFound
 * @date 2021-11-12
 */
@Service
public class SystemUserServiceImpl implements ISystemUserService
{
    @Autowired
    private SystemUserMapper systemUserMapper;

    /**
     * 查询业务登录
     *
     * @param id 业务登录主键
     * @return 业务登录
     */
    @Override
    public SystemUser selectSystemUserById(Long id)
    {
        return systemUserMapper.selectSystemUserById(id);
    }

    /**
     * 查询业务登录列表
     *
     * @param systemUser 业务登录
     * @return 业务登录
     */
    @Override
    public List<SystemUser> selectSystemUserList(SystemUser systemUser)
    {
        return systemUserMapper.selectSystemUserList(systemUser);
    }

    @Override
    public int insertRegitst(SystemUser systemUser){
        SystemUser newUser=new SystemUser();
        newUser.setUsername(systemUser.getUsername());
        List<SystemUser> systemUsers = systemUserMapper.selectSystemUserList(newUser);
        if(systemUsers.size()==0){
            newUser.setPassword(systemUser.getPassword());
            newUser.setIsvalid(0);
            int i = systemUserMapper.insertSystemUser(newUser);
            if(i==1){
                return 200;
            }
            return 201;
        }
        return 202;
    }

    /**
     * 新增业务登录
     *
     * @param systemUser 业务登录
     * @return 结果
     */
    @Override
    public int insertSystemUser(SystemUser systemUser)
    {
        List<SystemUser> systemUsers=systemUserMapper.selectSystemUserList(systemUser);
        if(systemUsers==null) {
            return systemUserMapper.insertSystemUser(systemUser);
        }else{
            return 0;
        }
    }

    /**
     * 修改业务登录
     *
     * @param systemUser 业务登录
     * @return 结果
     */
    @Override
    public int updateSystemUser(SystemUser systemUser)
    {
        return systemUserMapper.updateSystemUser(systemUser);
    }



    /**
     * 删除业务登录信息
     *
     * @param id 业务登录主键
     * @return 结果
     */
    @Override
    public int deleteSystemUserById(Long id)
    {
        return systemUserMapper.deleteSystemUserById(id);
    }


   @Override
    public SystemUser selectLogin(SystemUser systemUser){
        return systemUserMapper.selectLogin(systemUser);
    };

//    @Override
//    public int registerUser(SystemUser systemUser){
//        SystemUser user = systemUserDAO.selectByPrimaryKey(systemUser);
//        if(!systemUser.getUserName().isEmpty()&&user.getUserName().isEmpty()) {
//            systemUser.setIsvalid(0);
//            return systemUserDAO.insertSelective(systemUser);
//        }
//        return systemUserDAO.insertSelective(systemUser);
//    }
}
